<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作业7</title>
    <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
</head>
<form action="">
    <input id="username" type="text" name="username" placeholder="请输入用户名">
    <span id="s_username"></span><br>
</form>
<body>
<script type="text/javascript">
    var data=[
        {userExist:true, msg:"用户不存在"},
        {userExist:false, msg:"用户已存在"}
    ]
    $(function(){
        $("#username").blur(function(){
            var username = $(this).val();
            $.get("",{username:username},function(){
                var id=parseInt(Math.random()*2);
                if(data[id].userExist){
                    $("#s_username").html(data[id].msg).css("color","red");
                }else{
                    $("#s_username").html(data[id].msg).css("color","green");
                }
            })
        })
    })

</script>
</body>
</html>